import {useState} from 'react'

function Head(props) {

  function addItem(e) {
    if(e.keyCode!=13) return
    if(e.target.value==''){
      alert('请输入内容')
      return
    } 
    props.addItem(e.target.value)
    e.target.value=''
  }

  return (
    <>
      <header className="header">
        <h1 >todos</h1>
        <input
          type="text"
          className="new-todo"
          placeholder="What needs to be done?"
          onKeyUp={addItem}
        />
      </header>
    </>
  )


}

export default Head